class Solution {
public:
    vector<int> relativeSortArray(vector<int>& arr1, vector<int>& arr2) {
        unordered_map<int,int> ump;
        for(int i = 0;i < arr2.size();i++){
            ump[arr2[i]] = i;
        }
        
        sort(arr1.begin(),arr1.end(),[&](int& a,int& b)->bool{
            if(ump.count(a)){
                return ump.count(b) ? ump[a] < ump[b] : true;
            }else{
                return ump.count(b) ? false : a < b;
            }
        });
        return arr1;
    }
};
